//
//  YPLoginValidationProtocol.swift
//  YPSwift
//
//  Created by jerry on 2020/5/23.
//  Copyright © 2020 ogawa. All rights reserved.
//

import Foundation

enum YPLoginValidationResult {
    case ok(message:String)
    case empty
    case validating
    case failed(message:String)
}

protocol YPLoginLoginValidationProtocol {
    /// 用户名验证
    func validateUsername( _ username:String)  -> YPLoginValidationResult
    /// 密码验证
    func validatePassword( _ password:String)  -> YPLoginValidationResult
}

protocol YPLoginRegisterValidationProtocol :YPLoginLoginValidationProtocol {
    /// 手机号 验证
    func validatePhone( _ username:String)  -> YPLoginValidationResult
    /// 短信验证码 合法性验证
    func validateMsgCode( _ msgCode:String)  -> YPLoginValidationResult
    /// 再次密码 合法性验证
    func validateRepeatPassword( _ password:String,repeatPassword:String)  -> YPLoginValidationResult
}

extension YPLoginValidationResult {
    
    var isValid: Bool {
        switch self {
        case .ok:
            return true
        default:
            return false
        }
    }

    var notEmpty: Bool {
        switch self {
        case .empty:
            return false
        default:
            return true
        }
    }
    
    var message: String{
        switch self {
        case .failed(let message):
            return message
        default:
            return ""
        }
    }
    
}



